/**
 * 请求拦截器
 */
import {
  Injectable,
  NestInterceptor,
  ExecutionContext,
  CallHandler,
} from '@nestjs/common';
import { HerinHandle } from 'src/types/type/request.type';
import { ParamFormat } from '../../class/param/param.class';

@Injectable()
export class RequestInterceptor implements NestInterceptor {
  private _herin: HerinHandle = {
    ip: '',
    skip: 0,
    limit: 1000,
    findObj: {},
    project: {},
    sort: {},
    join: '',
    joinProject: '',
    keyword: '',
  };

  intercept(context: ExecutionContext, next: CallHandler) {
    const request = context.switchToHttp().getRequest();

    this._herin = ParamFormat.format(request.query);

    // 通用请求参数
    request['herin'] = this._herin;
    return next.handle();
  }
}
